<template>
	<view>
		<u-sticky bgColor="#fff">
			<u-tabs lineColor="#FFB800" lineWidth="15" :activeStyle="{
			             color: '#ff0000',
			             fontWeight: 'bold',
			             transform: 'scale(1.05)'
			         }" :inactiveStyle="{
			             color: '#666666',
			             transform: 'scale(1)'
			         }" :list="list1" @change="tabChage"></u-tabs>
		</u-sticky>
		<view class="mainpadding2">
			<view class="margin_top flexbetween zhizuotop radius" v-show="tabsId==2" @click="beihuodetail()">
				<view class="flexleft">
					<image src="../../static/image/system/bei.png" mode="" style="width: 50rpx;height: 50rpx;"></image>
					<view class="huang_text main_size bold margin_left1">查看製作詳情</view>
				</view>
				<u-icon name="arrow-right" color="#FF8505" size="12"></u-icon>
			</view>
			<view class="flexcenter margin_top" v-show="tabsId==3">
				<!-- <view class="all1" :class="lable===''?'checkall':''" @click="changelable('')">全部</view>
				<view class="all4" :class="lable==2?'checkall':''" @click="changelable(2)">内用</view> -->
				<view class="all1 dingwei" :class="lable==2?'checkall':''" @click="changelable(2)">内用
					<view class="box flexleft">
						<u-badge max="99" :value="orderDataMsg.dch_num2"></u-badge>
					</view>
				</view>
				<view class="all2 dingwei" :class="lable==1?'checkall':''" @click="changelable(1)">自取
					<view class="box flexleft">
						<u-badge max="99" :value="orderDataMsg.dch_num1"></u-badge>
					</view>
				</view>
				<view class="all3 dingwei" :class="lable===0?'checkall':''" @click="changelable(0)">外送
					<view class="box flexleft">
						<u-badge max="99" :value="orderDataMsg.dch_num0"></u-badge>
					</view>
				</view>
			</view>
			<view class="flexcenter margin_top" v-show="tabsId==4">
				<view class="all1" :class="status=='6'?'checkall':''" @click="changestatus('6')">待接單</view>
				<view class="all3" :class="status=='7,8'?'checkall':''" @click="changestatus('7,8')">配送中</view>
			</view>
			<view class="flexcenter" v-if="!list.data.length">
				<view class="placeholderimage" style="margin-top: 100rpx;"></view>
			</view>
			<template v-if="tabsId==3 && lable==2">
				<view class="mainpadding_top ffffff radius" v-for="item in list.data" :key="item.id">
					<view class="flexbetween">
						<view class="flexleft">
							<view style="font-size: 40rpx;color: #37a621;margin-right: 10rpx;" class="bold"
								v-if="item.ordergoods.order_type==2">預</view>
							<view style="font-size: 40rpx;color: #019891;margin-right: 10rpx;" class="bold"
								v-if="item.ordergoods.order_type==3">時</view>
							<view class="margin_right lableradius neiyong" v-if="item.ordergoods.type==2">内用</view>
							<view class="margin_right hong_text titletext bold">#{{item.ordergoods.call_no}}</view>
						</view>
						<view class="hong_text titletext bold"
							v-if="item.ordergoods.type==2&&item.ordergoods.desk && item.ordergoods.desk!=-1">
							{{item.ordergoods.desk}}
						</view>
					</view>
					<view class="flexleft margin_top">
						<view class="listleftimg radius margin_right">
							<image class="listleftimg radius" :src="item.logoimage_text" mode=""></image>
						</view>
						<view style="width: 100%;">
							<view class="hei_text main_size bold">{{item.goods_name}}</view>
							<view class="xiaohui flexbetween" v-if="item.wei || item.hei">
								<text>尺寸：{{item.wei}}*{{item.hei}}</text>
								<text>用量：{{item.formulacount}}{{item.size}}</text>
							</view>
							<view class="xiaohui" v-if="item.spunatname">規格：{{item.spunatname}}</view>
							<view class="flexbetween">
								<view class="main_size huang_text bold">
									${{Number(item.d_price).toFixed(0)}}&nbsp;&nbsp;&nbsp;x{{item.num}}</view>
								<view class="xiaohuang">${{Number(item.price).toFixed(0)}}</view>
							</view>
						</view>
					</view>
					<view class="flexright">
						<view class="listbtnhuang margin_top2 margin_right2" @click.stop="tongzhi(item.user_id)">通知
						</view>
						<view class="listbtnhuang margin_top2" @click.stop="singleShipmentny(item)">出貨</view>
					</view>
				</view>
			</template>
			<template v-else>
				<view class="mainpadding_top ffffff radius" v-for="item in list.data" :key="item.id"
					@click="jumpdetai(item.id)">
					<view class="flexbetween">
						<view class="flexleft">
							<view style="font-size: 40rpx;color: #37a621;margin-right: 10rpx;" class="bold"
								v-if="item.order_type==2">預</view>
							<view style="font-size: 40rpx;color: #019891;margin-right: 10rpx;" class="bold"
								v-if="item.order_type==3">時</view>

							<view class="margin_right lableradius waisong" v-if="item.type==0">外送</view>
							<view class="margin_right lableradius ziqu" v-if="item.type==1">自取</view>
							<view class="margin_right lableradius neiyong" v-if="item.type==2">内用</view>
							<view class="margin_right hong_text titletext bold">#{{item.call_no}}</view>
							<view class="hong_text titletext bold" v-if="item.type==2&&item.desk && item.desk!=-1">
								{{item.desk}}
							</view>
						</view>
						<view class="hong_text main_size" v-show="item.status==0">待支付</view>
						<view class="hong_text main_size" v-show="item.status==1">待接單</view>
						<view class="hong_text main_size" v-show="item.status==2">製作中</view>
						<view class="hong_text main_size" v-show="item.status==5">待出貨</view>
						<view class="huang_text main_size" v-show="item.status==6">待接單</view>
						<view class="huang_text main_size" v-show="item.status==8&&item.ps_type==0">物流配送</view>
						<view class="huang_text main_size"
							v-show="item.status==8&&(item.ps_type==1 || item.ps_type==2)">配送中
						</view>
						<view class="huang_text main_size" v-show="item.status==7&&item.ps_type==1">商家自送</view>
						<view class="huang_text main_size" v-show="item.status==7&&item.ps_type==2">騎手外送</view>
						<view class="huang_text main_size" v-show="item.status==9">已送达</view>
						<view class="huang_text main_size" v-show="item.status==87">待完成</view>
						<view class="lv_text main_size" v-show="item.status==88">已完成</view>

						<view class="hui_text main_size" v-show="item.status==97">已退款</view>
						<view class="hui_text main_size" v-show="item.status==99">已取消</view>
					</view>
					<view class="margin_top2 flexbetween xiaohui">
						<view class="yihang" style="width: 360rpx;">{{item.order_sn}}</view>
						<view>{{secondDate(item.createtime,0,0)}}</view>
					</view>
					<view class="margin_top2 flexbetween" v-if="item.opentype!=-1">
						<view class="flexleft">
							<view class="lanlable" v-if="item.opentype==0">紙本</view>
							<view class="lanlable" v-if="item.opentype==1">載具</view>
							<view class="lanlable" v-if="item.opentype==2">統編</view>
							<view class="lanlable" v-if="item.opentype==3">捐贈</view>
							<view v-if="item.tbcode"
								class="bold xiaolan margin_left1 ershib">{{item.tbcode}}</view>
						</view>
						<div class="flexright" v-if="item.fpinfo && item.opentype!=-1">
							<text class="weikailist" v-if="item.fpinfo && item.fpinfo.is_ly==1">未列印</text>
							<text class="yikailist" v-if="item.fpinfo && item.fpinfo.is_ly==2">已列印</text>
							<view class="bold  ershib margin_right1" :class="item.fpinfo.status==3?'xiaohong':'xiaolan'">
								發票號碼：{{item.fpinfo.invoice_number}}</view>
							<view class="xiaohong bold ershib" v-if="item.fpinfo.status==3">作廢</view>
						</div>
					</view>
					<view class="margin_top2 flexbetween xiaohui" v-if="item.type==2">
						<view>用餐時間：{{secondDate(item.draktime,0,0)}}</view>
						<!-- order_type订單类型:1=普通订單,2=预约订單,3=吃到饱订單,4=pos点餐,5=加总点單、 -->
						<view v-if="!item.cdbjhsf_data">
							合計{{Number(item.adult)+Number(item.old)+Number(item.child)}}人</view>
						<view v-if="item.cdbjhsf_data">合計{{returnycNum(item.cdbjhsf_data)}}人
						</view>
					</view>
					<view class="flexbetween margin_top" v-if="item.paypz_image">
						<view class="xiaohei main_size">支付憑證</view>
						<image class="listleftimg1 radius" :src="item.paypz_image_text" mode=""
							@click.stop="lbtpriview(0,[item.paypz_image_text])"></image>
					</view>
					<view class="xiaohui flexright margin_top bold" v-if="item.type==1 && item.status==88">
						<text v-if="Number(item.askfortime)">取：{{secondDate(item.askfortime,0,0)}}</text>
						<text v-if="!Number(item.askfortime)">取：{{secondDate(item.createtime,0,0)}}</text>
					</view>
					<view class="xiaohui margin_top bold textright">
						共{{item.total_num || 0}}件，合計：
						<text class="xiaohuang">${{item.countmoney || 0}}</text>
						<text v-if="item.type==0">，運費${{item.freight_price || 0}}</text>
						<text>，優惠${{item.yh_money || 0}}</text>
					</view>
					<view class="xiaohei margin_top1 bold textright"><text
							class="xiaohong">已付：${{Number(item.paymoney)+Number(item.shop_user_price) || 0}}，未付：${{item.zhuimoney || 0}}</text>，退款：${{item.tuiprice || 0}}
					</view>
					<view class="flexright margin_top flex_wrap">
						<view class="huang_text main_size bold margin_left2" v-show="item.paytype==1 && item.status!=0">
							點數支付
						</view>
						<view class="huang_text main_size bold margin_left2" v-show="item.paytype==2">多元支付
						</view>
						<view class="huang_text main_size bold margin_left2" v-show="item.paytype==3">現金支付
						</view>
						<view class="huang_text main_size bold margin_left2" v-show="item.paytype==4">信用卡
						</view>
						<view class="huang_text main_size bold margin_left2" v-show="item.paytype==5">Line Pay線上支付
						</view>
						<view class="huang_text main_size bold margin_left2" v-show="item.paytype==6">街口線上支付
						</view>
						<view class="huang_text main_size bold margin_left2" v-show="item.paytype==7">街口線下支付
						</view>
						<view class="huang_text main_size bold margin_left2" v-show="item.paytype==8">Line Pay線下支付
						</view>
						<view class="huang_text main_size bold margin_left2" v-show="item.paytype==9">Line Pay二維碼支付
						</view>
						<view class="huang_text main_size bold margin_left2" v-show="item.paytype==10">街口二維碼支付
						</view>
						<view class="huang_text main_size bold margin_left2" v-show="item.paytype==11">全支付線下支付
						</view>
						<view class="listbtnhui margin_left2" @click.stop="cancelorder(item)" v-show="item.status==0">
							取消訂單
						</view>
						<view class="listbtnhuang margin_left2" @click.stop="xianjinwfsk(item)"
							v-show="item.status==0 && item.order_type!=4 && item.order_type!=5">
							確認收款
						</view>
						<!-- 加總結賬/pos點餐重新收款 -->
						<view class="listbtnhuang margin_left2" @click.stop="cxsk(item)"
							v-show="item.status==0 && (item.order_type==4 || item.order_type==5)">
							重新收款
						</view>
						<view class="listbtnhuang margin_left2" v-show="item.status==1"
							@click.stop="suretakOrder(item)">
							確認接單</view>
						<view class="listbtnhui margin_left2" v-show="item.status==2"
							@click.stop="aginDyOrder(item.id)">
							收據列印
						</view>
						<view class="listbtnhui margin_left2" v-show="item.status==2" @click.stop="workprint(item.id)">
							工作站列印
						</view>
						<view class="listbtnhuang margin_left2" v-show="item.status==88 && item.zhuimoney==0"
							@click.stop="tuikuanModal=true;currentid=item.id;currentAllprice=item.countmoney;currentAll=item">
							退款
						</view>
						<view class="listbtnhuang margin_left2" v-show="item.type==2&&item.status==5"
							@click.stop="allShipment(item)">一次出貨
						</view>
						<view class="listbtnhuang margin_left2" v-show="item.type==1&&item.status==5"
							@click.stop="takeGoods(item.id,item.user_id)">通知提貨</view>
						<view class="listbtnhuang" @click.stop="wuliupsFn(item.id)"
							v-show="item.type==0&&item.status==5">
							物流配送
						</view>
						<view class="listbtnhuang margin_left2" @click.stop="phone(item.takeaway.phone)"
							v-show="(item.status==7&&item.ps_type==1)||(item.status==7&&item.ps_type==2)">聯係騎手</view>
						<view class="listbtnhuang margin_left2" @click.stop="chakanwlFn(item)"
							v-show="item.status==8&&item.ps_type==0">查看物流</view>
						<view class="listbtnhui margin_left2" v-show="item.type==0&&item.status==5"
							@click.stop="qsws(item.id)">騎手外送</view>
						<view class="listbtnhuang margin_left2" @click.stop="shopDeliver(item.id)"
							v-show="item.type==0&&item.status==5">商家自送</view>
						<!--  -->
						<view class="listbtnhuang margin_left2"
							v-show="item.type==2 && (item.status==2 || item.status==5 || item.status==87) && item.order_type!=3"
							@click.stop="diancan(item)">點餐
						</view>
						<view class="listbtnhuang margin_left2"
							v-show="(item.status==87 || item.status==88) && (Number(item.zhuimoney)!=0) && item.order_type!=2 && item.order_type!=3"
							@click.stop="xianjinsk(item)">確認收款</view>
						<view class="listbtnhuang margin_left2" v-show="item.type==1&&item.status==87"
							@click.stop="tongzhith(item.id,item.user_id)">通知提貨</view>
						<view class="listbtnhuang margin_left2" v-show="item.status==87 && item.zhuimoney==0"
							@click.stop="wanchengfw(item)">完成服務</view>
					</view>
				</view>
			</template>
		</view>
		<u-popup :show="qrskshow" round="30" mode="center" closeable @close="qrskshow=false">
			<view class="mainpadding" style="min-width: 700rpx;max-width: 700rpx;">
				<view class="flexleft margin_top">
					<view class="bold hei_text" style="font-size: 52rpx;">總計金額：</view>
					<view class="bold xiaohei" style="font-size: 52rpx;" v-text="totalPrice"></view>
				</view>
				<view class="flexleft margin_top">
					<view class="bold hei_text" style="font-size: 52rpx;">應找金額：</view>
					<view class="bold xiaohong" style="font-size: 52rpx;" v-text="zhaoling"></view>
				</view>
				<view class="margin_top sytbox">
					<input type="text" class="sytsrk" placeholder="實收金額" disabled="" v-model="zhifuje" />
				</view>
				<view class="flexbetween flex-wrap margin_top">
					<view class="flexcenter" style="width: 33.33%;" v-for="item in numList" :key="item"
						@click="numtap(item)">
						<view class="itembox flexcenter">{{item}}
						</view>
					</view>
					<view class="flexcenter" style="width: 33.33%;">
						<view class="itembox delitem flexcenter" @click="delnum">DEL</view>
					</view>

				</view>
				<view class="flexbetween margin_top">
					<view class="payTypeClass xiaobai" style="background-color: #00a0e9;" @click="submit(4)">信用卡</view>
					<view class="payTypeClass xiaobai" style="background-color: #ec7301;" @click="dypay">多元支付</view>
					<view class="payTypeClass xiaobai" style="background-color: #db0f62;" @click="submit(1)">錢包點數</view>
					<view class="payTypeClass xiaobai" style="background-color: #a70182;" @click="submit(3)">現金支付</view>
				</view>
			</view>
		</u-popup>
		<!-- 物流配送 -->
		<u-modal :show="wlpsModal.show" title="物流配送" confirmColor="#FF8505" :closeOnClickOverlay="true" confirmText="確認"
			cancelText="取消" @close="wlpsModal.show=false" @confirm="wlpsconfirm">
			<view class="slot-content flexbetween mainpadding_top" style="border: 1rpx solid #f5f5f5;">
				<input type="text" placeholder="請輸入物流單號" style="width: 100%;" v-model="wlpsModal.text">
				<u-icon name="scan" color="#FF8505" size="28" @click="saoma()"></u-icon>
			</view>
		</u-modal>
		<u-modal :show="tuikuanModal" title="" confirmColor="#FF8505" :closeOnClickOverlay="true" confirmText="確認"
			cancelText="取消" @close="tuikuanModal=false" @confirm="tuikuanconfirm">
			<view class="slot-content flexcolumn mainpadding2">
				<view class="textcenter xiaohuang bold" style="font-size: 40rpx;">訂單總金額：${{currentAllprice}}</view>
				<view class="flexbetween margin_top5">
					<view class="hei_text main_size">退款金額:</view>
					<input type="number" placeholder="請輸入退款金額" class="textcenter xiaohuang bold"
						style="text-align: right;font-size: 40rpx;width: 60%;" v-model="tui_price">
				</view>
				<view class="flexbetween margin_top">
					<view class="hei_text main_size">退款密碼:</view>
					<input type="password" placeholder="請輸入退款密碼" v-model="paypassword" style="text-align: right;">
				</view>
			</view>
		</u-modal>
		<!-- 查看物流 -->
		<u-modal :show="ckwlModal.show" title="查看物流" confirmColor="#FF8505" confirmText="點擊複製"
			:closeOnClickOverlay="true" @close="ckwlModal.show=false" @confirm="copy(ckwlModal.text)">
			<view class="slot-content flexcenter mainpadding_top">{{ckwlModal.text}}</view>
		</u-modal>
		<u-popup :show="cxskshow" mode="center" round="10" @close="cxskshow=false" closeable>
			<view class="flexcenter mainpadding bold">重新收款</view>
			<view class="flexbetween mainpadding2">
				<view class="payTypeClass xiaobai margin_right" style="background-color: #00a0e9;"
					@click="submitcxsk(4)">信用卡</view>
				<view class="payTypeClass xiaobai margin_right" style="background-color: #ec7301;" @click="dypay">多元支付
				</view>
				<view class="payTypeClass xiaobai margin_right" style="background-color: #db0f62;"
					@click="submitcxsk(1)">錢包點數</view>
				<view class="payTypeClass xiaobai" style="background-color: #a70182;" @click="submitcxsk(3)">現金支付</view>
			</view>
		</u-popup>
		<u-modal :show="dymodalshow" title="請使用掃描器掃描" confirmColor="#fbb826" confirmText="關閉"
			@confirm="dymodalshow=false">
			<view class="slot-content">
				<view class="mainpadding">
					<view class="flexbetween"
						style="border: 1rpx solid #fbb826; padding: 10rpx 20rpx;border-radius: 10rpx;">
						<input type="text" placeholder="" class="xiaohei" :focus="dyinputfocus" :auto-focus="true"
							v-model="dycode" @confirm="dykoukuan" confirm-type="search" />
						<view class="" @click="dysaoma()">
							<u-icon name="scan" color="#fbb826" size="22"></u-icon>
						</view>
					</view>
				</view>
			</view>
		</u-modal>
		<fukuanmsg :show="messagefk.fkshow" :paystatus="messagefk.paystatus"></fukuanmsg>
	</view>
</template>
<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		name: "goodsorderzj",
		data() {
			return {
				shop_id: uni.getStorageSync("shop_id"),
				list1: [{
					id: 0,
					name: '待支付',
					badge: {
						value: 0,
					}
				}, {
					id: 1,
					name: '待接單',
					badge: {
						value: 0,
					}
				}, {
					id: 2,
					name: '製作中',
					badge: {
						value: 0,
					}
				}, {
					id: 3,
					name: '待出貨',
					badge: {
						value: 0,
					}
				}, {
					id: 4,
					name: '配送中',
					badge: {
						value: 0,
					}
				}, {
					id: 5,
					name: '待完成',
					badge: {
						value: 0,
					}
				}, {
					id: 6,
					name: '已完成',
					badge: {
						value: 0,
					}
				}, ],
				tabsId: 0, //默认待支付
				type: 0, //订單类型:0=外送,1=自取,2=内用
				status: 0, //订單状态:0 待支付1 已支付 2已接單  3 已出货/待取货 4已取货 5待出货 99已取消 88订單完成
				lable: '',
				wlpsModal: { //物流配送
					show: false,
					text: "",
				},
				ckwlModal: { //查看物流
					show: false,
					text: "",
				},
				page: 1,
				list: {
					data: []
				},
				id: "", //物流配送的订單id
				ztNum: 0,
				// 訂單退款
				tuikuanModal: false,
				currentid: "",
				currentAllprice: "",
				currentAll: {},
				paypassword: "",
				tui_price: "",
				pos_show: false,
				orderDataMsg: {},
				totalPrice: 0, //订單总金额
				zhifuje: "",
				qrskshow: false,
				numList: [1, 2, 3, 4, 5, 6, 7, 8, 9, "00", 0],
				cxskshow: false,
				cxskitem: {},
				dymodalshow: false,
				dycode: "",
				dyinputfocus: false,
				messagefk: {
					fkshow: false,
					paystatus: 1, //1成功，2失败
				},
				issubmit: false
			}
		},
		watch: {
			"wlpsModal.show"(newval) {
				if (!newval) {
					this.wlpsModal.text = ""
				}
			}
		},
		onLoad() {
			uni.$on("getwlcode", data => {
				if (this.wlpsModal.show) {
					this.wlpsModal.text = data
				}
			})
			uni.$on("jiazongsacnCode", data => {
				this.dycode = data
				this.dykoukuan()
			})
			uni.$on("possacnCode", data => {
				this.dycode = data
				this.dykoukuan()
			})
		},
		onUnload() {
			uni.$off("getwlcode")
			uni.$off("jiazongsacnCode")
			uni.$off("possacnCode")
		},
		computed: {
			zhaoling() {
				let price = Number(this.zhifuje) - Number(this.totalPrice)
				if (price >= 0) {
					return price
				} else {
					return 0
				}
			}
		},
		methods: {
			returnycNum(val) {
				let cdbjhsf_data = JSON.parse(val)
				let num = 0
				cdbjhsf_data.forEach(item => {
					num = Number(num) + Number(item.num)
				})
				return num
			},
			dypay(val) {
				this.cxskshow = false
				this.qrskshow = false
				this.dymodalshow = true
				this.dyinputfocus = true
			},
			dykoukuan() { //掃碼槍或輸入回車扣款
				if (this.issubmit) return
				uni.showLoading({
					mask: true,
					title: "請稍後"
				})
				this.dymodalshow = false
				this.dyinputfocus = false
				let goods_list_ids = []
				this.cxskitem.goods_data.forEach(item => {
					goods_list_ids.push(item.id)
				})
				this.issubmit = true
				if (this.cxskitem.order_type == 4 || this.cxskitem.order_type == 1) { //pos重新付款
					if (this.dycode.substring(0, 2) == 'P1' || this.dycode.substring(0, 2) == 'P2') { //全支付
						httpRequest.request("/api/ordergoods/qxpayScan", "POST", {
							shop_id: uni.getStorageSync("shop_id"),
							id: this.cxskitem.id,
							pay_token: this.dycode
						}).then(res => {
							uni.hideLoading()
							if (res.code == 1) {
								this.messagefk = {
									fkshow: true,
									paystatus: 1
								}
								setTimeout(() => {
									this.messagefk = {
										fkshow: false,
										paystatus: 1
									}
								}, 1000)
								this.dycode = ""
								this.getList()
							} else {
								this.issubmit = false
								this.messagefk = {
									fkshow: true,
									paystatus: 2
								}
								setTimeout(() => {
									this.messagefk = {
										fkshow: false,
										paystatus: 2
									}
								}, 1000)
								this.dycode = ""
							}
						})
					}
					if (this.dycode.substring(0, 2) == 22) { //街口支付
						httpRequest.request("/api/ordergoods/jkoPayScan", "POST", {
							shop_id: uni.getStorageSync("shop_id"),
							id: this.cxskitem.id,
							CardToken: this.dycode,
							goods_list_ids: goods_list_ids.join()
						}).then(res => {
							uni.hideLoading()
							if (res.code == 1) {
								this.messagefk = {
									fkshow: true,
									paystatus: 1
								}
								setTimeout(() => {
									this.messagefk = {
										fkshow: false,
										paystatus: 1
									}
								}, 1000)
								this.dycode = ""
								this.getList()
							} else {
								this.issubmit = false
								this.messagefk = {
									fkshow: true,
									paystatus: 2
								}
								setTimeout(() => {
									this.messagefk = {
										fkshow: false,
										paystatus: 2
									}
								}, 1000)
								this.dycode = ""
								// this.http.modal('扣款失敗', res.msg, false, (res) => {})
							}
						})
					}
					if (this.dycode.substring(0, 2) == 38) { //line支付
						httpRequest.request("/api/ordergoods/linepayScan", "POST", {
							shop_id: uni.getStorageSync("shop_id"),
							id: this.cxskitem.id,
							oneTimeKey: this.dycode,
							goods_list_ids: goods_list_ids.join()
						}).then(res => {
							uni.hideLoading()
							if (res.code == 1) {
								this.messagefk = {
									fkshow: true,
									paystatus: 1
								}
								setTimeout(() => {
									this.messagefk = {
										fkshow: false,
										paystatus: 1
									}
								}, 1000)
								this.dycode = ""
								this.getList()
							} else {
								this.issubmit = false
								this.messagefk = {
									fkshow: true,
									paystatus: 2
								}
								setTimeout(() => {
									this.messagefk = {
										fkshow: false,
										paystatus: 2
									}
								}, 1000)
								this.dycode = ""
							}
						})
					}
				}
				if (this.cxskitem.order_type == 5) { //加总结账重新付款
					if (this.dycode.substring(0, 2) == 'P1' || this.dycode.substring(0, 2) == 'P2') { //全支付
						httpRequest.request("/api/ordergoods/qxpayScan", "POST", {
							shop_id: uni.getStorageSync("shop_id"),
							id: this.cxskitem.id,
							pay_token: this.dycode
						}).then(res => {
							uni.hideLoading()
							if (res.code == 1) {
								this.messagefk = {
									fkshow: true,
									paystatus: 1
								}
								setTimeout(() => {
									this.messagefk = {
										fkshow: false,
										paystatus: 1
									}
								}, 1000)
								this.dycode = ""
								this.getList()
							} else {
								this.issubmit = false
								this.messagefk = {
									fkshow: true,
									paystatus: 2
								}
								setTimeout(() => {
									this.messagefk = {
										fkshow: false,
										paystatus: 2
									}
								}, 1000)
								this.dycode = ""
							}
						})
					}
					if (this.dycode.substring(0, 2) == 22) { //街口支付
						this.http.request("/api/ordergoods/jkoPayScan", "POST", {
							shop_id: uni.getStorageSync("shop_id"),
							id: this.cxskitem.id,
							CardToken: this.dycode,
						}).then(res => {
							uni.hideLoading()
							if (res.code == 1) {
								this.dymodalshow = false
								this.messagefk = {
									fkshow: true,
									paystatus: 1
								}
								setTimeout(() => {
									this.messagefk = {
										fkshow: false,
										paystatus: 1
									}
								}, 1000)
								this.dycode = ""
								this.getList()
							} else {
								this.issubmit = false
								this.messagefk = {
									fkshow: true,
									paystatus: 2
								}
								setTimeout(() => {
									this.messagefk = {
										fkshow: false,
										paystatus: 2
									}
								}, 1000)
								this.dycode = ""
								// this.http.modal('扣款失敗', res.msg, false, (res) => {})
							}
						})
					}
					if (this.dycode.substring(0, 2) == 38) { //linepay支付
						this.http.request("/api/ordergoods/linepayScan", "POST", {
							shop_id: uni.getStorageSync("shop_id"),
							id: this.cxskitem.id,
							oneTimeKey: this.dycode,
						}).then(res => {
							uni.hideLoading()
							if (res.code == 1) {
								this.dymodalshow = false
								this.messagefk = {
									fkshow: true,
									paystatus: 1
								}
								setTimeout(() => {
									this.messagefk = {
										fkshow: false,
										paystatus: 1
									}
								}, 1000)
								this.dycode = ""
								this.getList()
							} else {
								this.issubmit = false
								this.messagefk = {
									fkshow: true,
									paystatus: 2
								}
								setTimeout(() => {
									this.messagefk = {
										fkshow: false,
										paystatus: 2
									}
								}, 1000)
								this.dycode = ""
							}
						})
					}
				}
			},
			dysaoma() { //掃碼扣款
				let goods_list_ids = []
				this.cxskitem.goods_data.forEach(item => {
					goods_list_ids.push(item.id)
				})
				if (this.cxskitem.order_type == 4) { //pos重新付款
					uni.navigateTo({
						url: "/pages/pospay/pospay"
					})
				}
				if (this.cxskitem.order_type == 5) { //加总结账重新付款
					uni.navigateTo({
						url: "/pages/jiazongpay/jiazongpay"
					})
				}
			},
			cxsk(item) {
				this.cxskitem = item
				this.cxskshow = true
			},
			submitcxsk(val) {
				this.cxskshow = false
				if (val == 1) {
					uni.navigateTo({
						url: "/pages/dianshupay/dianshupay?type=1&id=" + this.cxskitem.id
					})
					return false
				}
				let arr = []
				this.http.request('/api/ordergoods/otherPayOrder', 'GET', {
					id: this.cxskitem.id,
					paytype: val,
				}).then(res => {
					uni.hideLoading()
					this.http.toast(res.msg)
					if (res.code == 1) {
						this.getList()
					}
				})
			},
			submit(val) {
				this.qrskshow = false
				if (this.issubmit) return
				if (val == 1) {
					uni.navigateTo({
						url: "/pages/dianshupay/dianshupay?type=1&id=" + this.cxskitem.id
					})
					return false
				}
				this.issubmit = true
				this.http.request('/api/ordergoods/endzhuimoney', 'POST', {
					id: this.currentid,
					paytype: val
				}).then(res => {
					if (res.code == 1) {
						this.http.toast("確認收款完成")
						this.getList()
					} else {
						this.issubmit = false
						this.http.toast(res.msg)
					}
				})
			},
			numtap(item) {
				if (Number(item) == 0 && this.zhifuje == "") {
					return false
				}
				this.zhifuje = this.zhifuje + item
			},
			delnum() {
				let str = this.zhifuje;
				let newStr = str.slice(0, -1);
				this.zhifuje = newStr
			},
			componentInit() {
				console.log("商品訂單初始化成功");
				this.getList()
				this.getztnum()
				this.getInfo()
			},
			getInfo() {
				this.http.request("/api/shop/Shopdeail", "POST", {
					shop_id: uni.getStorageSync("shop_id"),
				}).then(res => {
					uni.setStorageSync("appkey", res.data.appkey)
					uni.setStorageSync("hy_type", res.data.hy_type)
					uni.setStorageSync("opentable_status", res.data.opentable_status)
					uni.setStorageSync("is_sdkfp", res.data.is_sdkfp)
					uni.setStorageSync("is_call_sdkfp", res.data.is_call_sdkfp)
					uni.setStorageSync("is_pos_sdkfp", res.data.is_pos_sdkfp)
					
					uni.setStorageSync("houtel_type", res.data.houtel_type)
					if (res.data.is_ny == 0 && res.data.is_zq == 0) {
						this.pos_show = false
					} else {
						this.pos_show = true
					}
				})
			},
			diancan(item) {
				uni.setStorageSync("order_goods_id", item.id)
				uni.navigateTo({
					url: "/pages/callOutOrder/xuanzefw?orderly=1"
				})
			},
			getorderMsg() {
				this.http.request('/api/ordergoods/orderData', 'POST', {
					shop_id: this.shop_id, //店鋪id
				}).then(res => {
					this.list1[0].badge.value = res.data.dzf_num
					this.list1[1].badge.value = res.data.djd_num
					this.list1[2].badge.value = res.data.zzz_num
					this.list1[3].badge.value = res.data.dch_num
					this.list1[4].badge.value = res.data.psz_num
					this.list1[5].badge.value = res.data.fwz_num
					this.list1[6].badge.value = res.data.ywc_num
					this.orderDataMsg = res.data
				})
			},
			jumpurl(url) {
				uni.navigateTo({
					url
				})
			},
			saoma() {
				uni.navigateTo({
					url: "/pages/workbench/scanywcode"
				})
			},
			getztnum() { //使用列表
				this.http.request('/api/shop/listtable', 'POST', {
					shop_id: this.shop_id, //店鋪id
				}).then(res => {
					if (res.code == 1) {
						this.ztNum = res.data.length
					} else {
						this.ztNum = 0
					}
				})
			},
			wanchengfw(item) {
				this.http.modal('', '是否確認完成服務', true, (res) => {
					if (res) {
						this.http.request('/api/ordergoods/neiendgoods', 'POST', {
							id: item.id,
						}).then(res => {
							if (res.code == 1) {
								this.http.toast("已完成服務")
								this.getList()
							} else {
								this.http.toast(res.msg)
							}
						})
					}
				})
			},
			xianjinsk(item) {
				uni.navigateTo({
					url: "/pages/goodsOrder/goodssk?total_price=" + item.zhuimoney + "&id=" + item.id
				})
				// if (item.order_type == 1) {
				// 	uni.navigateTo({
				// 		url: "/pages/goodsOrder/goodssk?total_price=" + item.zhuimoney + "&id=" + item.id
				// 	})
				// } else {
				// 	uni.navigateTo({
				// 		url: "/pages/yuYueOrder/yuyuesk?total_price=" + item.zhuimoney + "&id=" + item.ordermak_id
				// 	})
				// }
			},
			xianjinwfsk(item) {
				this.http.modal('', '請確認是否完成確認收款', true, (res) => {
					if (res) {
						this.http.request('/api/pay/quredypay', 'POST', {
							id: item.id,
						}).then(res => {
							if (res.code == 1) {
								this.http.toast("確認收款完成")
								this.getList()
							} else {
								this.http.toast(res.msg)
							}
						})
					}
				})
			},
			cancelorder(item) {
				this.http.modal('', '請確認是否取消當前訂單', true, (res) => {
					if (res) {
						this.http.request('/api/ordergoods/cancelOrder', 'GET', {
							id: item.id,
						}).then(res => {
							this.http.toast(res.msg)
							if (res.code == 1) {
								this.getList()
							}
						})
					}
				})
			},
			zuofei(id) {
				let data = {
					id
				}
				let url = '/api/shop/cancelShopFp'
				httpRequest.request(url, 'GET', data, false, false, true).then(res => {
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						this.getList()
					}
				})
			},
			getList(isPage, page) { //订單列表
				this.getorderMsg()
				this.$emit("zjchange", "")
				let _this = this
				let data = {
					page: page || 1,
					limit: 12,
					status: this.status,
					shop_id: this.shop_id,
					type: this.status == 5 ? this.type.toString() : "",
					tab_type: this.tabsId == 5 || this.tabsId == 6 ? 1 : 0
				}
				let url = "/api/Ordergoods/listOrdergoods"
				if (this.lable == 2 && this.tabsId == 3) {
					url = "/api/Ordergoods/getOrderGoodsList"
					delete data.type
					delete data.status
					delete data.tab_type
				}
				this.http.request(url, 'POST', data).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (this.tabsId != 3 && this.lable != 2) {
							resList.data.forEach(item => {
								let goods_allprice = 0
								item.goods_data.forEach(value => {
									value.logoimage = this.imgUrlUser + value.logoimage
									goods_allprice = Number(value.price) + Number(goods_allprice)
								})
								this.$set(item, "goods_allprice", goods_allprice)
							})
						}
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							_this.list = res.data
							_this.list.data = resList.data;
						}
					} else if (res.code == 0) {
						this.list.data = []
						// this.http.toast(res.msg)
					} else {
						this.http.toast('系統處理中，請稍後再試');
					}
				})
			},
			onReachBottomZj() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.getList(true, page);
			},
			tabChage(e) {
				this.tabsId = e.id
				if (this.tabsId == 3) {
					this.type = 2
					this.lable = 2
				} else if (this.tabsId == 4) {
					this.type = ""
					this.lable = ''
					this.status = "6"
					this.getList()
					return false
					// this.type = 3
				} else {
					this.type = ""
				}
				let obj = {
					"0": 0, //待支付
					"1": 1, //待接單
					"2": 2, //制作中
					"3": 5, //待出货
					"4": 4, //配送中
					"5": '2,87', //服务中
					"6": "9,88,97,99", //已完成
				}
				this.status = obj[this.tabsId]
				console.log(obj[this.tabsId], "status");
				this.getList()
			},
			changelable(val) {
				this.lable = val
				this.type = this.lable
				this.getList()
			},
			changestatus(val) {
				this.status = val
				this.getList()
			},
			// 订單详情
			jumpdetai(id) {
				uni.navigateTo({
					url: "/pages/goodsOrder/dingdanxq?id=" + id
				})
			},
			// 重新打印小票
			async aginDyOrder(id) {
				uni.showLoading({
					mask: true,
					title: "請稍後"
				})
				let res = await this.http.request('/api/ordergoods/aginDyOrder', 'POST', {
					id
				})
				uni.hideLoading()
				if (res.code == 1) {
					httpRequest.toast("已發送指令")
				} else {
					httpRequest.toast(res.msg)
				}
			},
			async workprint(id) {
				uni.showLoading({
					mask: true,
					title: "請稍後"
				})
				let res = await this.http.request('/api/ordergoods/workDy', 'POST', {
					id
				})
				uni.hideLoading()
				httpRequest.toast(res.msg)
			},
			// 確認接單
			async suretakOrder(item) {
				if (item.type == 2 && this.ztNum != 0 && Number(item.desk) <= 0) {
					let count = Number(item.adult) + Number(item.old) + Number(item.child)
					uni.navigateTo({
						url: `/pages/goodsOrder/xuanzezt?order_goods_id=${item.id}&count=${count}`
					})
					return false
				}
				let _this = this
				let res = await this.http.request('/api/Ordergoods/jieOrdergoods', 'POST', {
					id: item.id,
				})
				if (res.code == 1) {
					this.http.toast("接單成功")
					this.getList()
				} else if (res.code == 0) {
					this.http.toast(res.msg)
				} else {
					this.http.toast('系統處理中，請稍後再試');
				}
			},
			// 制作详情
			beihuodetail() {
				uni.navigateTo({
					url: "/pages/goodsOrder/beihuoxq"
				})
			},
			async singleShipment(value, item) { //單個出货
				let res = await this.http.request('/api/Ordergoods/shellgoods_n', 'POST', {
					id: value.id,
					order_goods_id: item.id
				})
				if (res.code == 1) {
					this.http.toast("出貨成功")
					this.getList()
				} else if (res.code == 0) {
					this.http.toast(res.msg)
				} else {
					this.http.toast('系統處理中，請稍後再試');
				}
			},
			async singleShipmentny(item) { //内用單個出货
				let res = await this.http.request('/api/Ordergoods/shellgoods_n', 'POST', {
					id: item.id,
					order_goods_id: item.ordergoods.id
				})
				if (res.code == 1) {
					this.http.toast("出貨成功")
					this.getList()
				} else if (res.code == 0) {
					this.http.toast(res.msg)
				} else {
					this.http.toast('系統處理中，請稍後再試');
				}
			},
			tongzhi(user_id) {
				uni.showLoading({
					mask: true,
					title: "請稍後"
				})
				this.http.requestuser('/api/ordergoods/callUsergetgood', 'GET', {
					user_id,
				}).then(res => {
					uni.hideLoading()
					if (res.code == 1) {
						httpRequest.toast(res.msg)
					}
				})
			},
			async allShipment(item) { //一次出货
				let res = await this.http.request('/api/Ordergoods/allgoods_n', 'POST', {
					id: item.id
				})
				if (res.code == 1) {
					this.http.toast("出貨成功")
					this.getList()
				} else {
					this.http.toast(res.msg)
				}
			},
			async takeGoods(id,user_id) { //確認提货
				this.tongzhith(id,user_id)
				let res = await this.http.request('/api/Ordergoods/endgoods', 'POST', {
					id
				})
				if (res.code == 1) {
					this.getList()
				} else {
					this.http.toast(res.msg)
				}
			},
			async tongzhith(order_id,user_id){
				let res = await this.http.request('/api/ordergoods/userGetFoods', 'POST', {
					order_id,
					user_id
				})
			},
			wuliupsFn(id) { //物流配送
				this.id = id
				this.wlpsModal.show = true
			},
			tuikuanconfirm() {
				if (this.tui_price == "") {
					this.http.toast("請輸入退款金額")
					return false
				}
				if (Number(this.currentAllprice) < Number(this.tui_price)) {
					this.http.toast("退款金額不能大於訂單合計金額")
					return false
				}
				if (this.paypassword == "") {
					this.http.toast("請輸入退款密碼")
					return false
				}
				this.tuikuanModal = false
				if (this.currentAll.paytype == 5) { //line pay线上退款
					this.http.request('/api/pay/LinePayRefound', 'POST', {
						id: this.currentid,
						paymoney: this.tui_price,
						paypassword: this.paypassword,
						shop_id: this.shop_id
					}).then(res => {
						this.currentid = ""
						this.tui_price = ""
						this.paypassword = ""
						this.http.toast(res.msg)
						if (res.code == 1) {
							this.getList()
						}
					})
				} else if (this.currentAll.paytype == 7) { //街口线下支付退款
					this.http.request('/api/pay/jkoPayScanRefound', 'POST', {
						id: this.currentid,
						paymoney: this.tui_price,
						paypassword: this.paypassword,
						shop_id: this.shop_id
					}).then(res => {
						this.currentid = ""
						this.tui_price = ""
						this.paypassword = ""
						this.http.toast(res.msg)
						if (res.code == 1) {
							this.getList()
						}
					})
				} else if (this.currentAll.paytype == 8) { //line pay线下退款
					this.http.request('/api/pay/LinePayScanRefound', 'POST', {
						id: this.currentid,
						paymoney: this.tui_price,
						paypassword: this.paypassword,
						shop_id: this.shop_id
					}).then(res => {
						this.currentid = ""
						this.tui_price = ""
						this.paypassword = ""
						this.http.toast(res.msg)
						if (res.code == 1) {
							this.getList()
						}
					})
				} else {
					this.http.request('/api/Ordergoods/tuiOrderPrice', 'POST', {
						order_goods_id: this.currentid,
						paymoney: this.tui_price,
						paypassword: this.paypassword
					}).then(res => {
						this.currentid = ""
						this.tui_price = ""
						this.paypassword = ""
						this.http.toast(res.msg)
						if (res.code == 1) {
							this.getList()
						}
					})
				}

			},
			async wlpsconfirm() { //物流配送確認
				if (this.wlpsModal.text == "") {
					this.http.toast("請輸入物流單號")
					return false
				}
				let res = await this.http.request('/api/Ordergoods/wlendgoods', 'POST', {
					id: this.id,
					shopfreight_num: this.wlpsModal.text
				})
				if (res.code == 1) {
					this.http.toast("送貨成功")
					this.getList()
				} else if (res.code == 0) {
					this.http.toast(res.msg)
				} else {
					this.http.toast('系統處理中，請稍後再試');
				}
				this.wlpsModal.show = false
			},
			async qsws(id) { //骑手外送
				let res = await this.http.request('/api/Ordergoods/qsendgoods', 'POST', {
					id
				})
				if (res.code == 1) {
					this.http.toast("送貨成功")
					this.getList()
				} else if (res.code == 0) {
					this.http.toast(res.msg)
				} else {
					this.http.toast('系統處理中，請稍後再試');
				}
			},
			async shopDeliver(id) { //商家自送
				let res = await this.http.request('/api/Ordergoods/shopendgoods', 'POST', {
					id
				})
				if (res.code == 1) {
					this.http.toast("送貨成功")
					this.getList()
				} else if (res.code == 0) {
					this.http.toast(res.msg)
				} else {
					this.http.toast('系統處理中，請稍後再試');
				}
			},
			// 查看物流
			chakanwlFn(item) {
				this.ckwlModal.show = true
				this.ckwlModal.text = item.shopfreight_num
			},
			copy(value) {
				this.ckwlModal.show = false
				uni.setClipboardData({
					data: value.toString(), //要被复制的内容
					success: () => {
						//复制成功的回调函数
						this.http.toast("複製成功")
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.payTypeClass {
		text-align: center;
		font-size: 28rpx;
		font-weight: bold;
		padding: 40rpx 0;
		width: 150rpx;
	}

	.box {
		position: absolute;
		top: -30rpx;
		right: 40rpx;
	}

	.posdc {
		background: linear-gradient(180deg, #ff9c01 0%, #ffe070 100%);
		color: #333;
		border: 1rpx solid #333;
		font-size: 28rpx;
		padding: 10rpx 15rpx;
		border-radius: 50rpx;
		line-height: 28rpx;
	}

	.posdcimg {
		width: 220rpx;
		height: 60rpx;
	}

	.listleftimg1 {
		width: 150rpx;
		min-width: 150rpx;
		height: 150rpx;
		position: relative;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.zhizuotop {
		padding: 15rpx 30rpx;
		border: 1rpx solid #FF8505;
	}

	.all1 {
		background: #fFF;
		border-radius: 11rpx 0rpx 0rpx 11rpx;
		font-size: 32rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FF8505;
		padding: 11rpx 38rpx;
		border: 2rpx solid #FF8505;
	}

	.all2 {
		background: #fFF;
		border-radius: 0rpx;
		font-size: 32rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FF8505;
		padding: 11rpx 38rpx;
		border: 2rpx solid #FF8505;
		border-right: none;
		border-left: none;
	}

	.all4 {
		background: #fFF;
		border-radius: 0rpx;
		font-size: 32rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FF8505;
		padding: 11rpx 38rpx;
		border: 2rpx solid #FF8505;
		border-left: none;
	}

	.all3 {
		background: #fFF;
		border-radius: 0rpx 11rpx 11rpx 0rpx;
		font-size: 32rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FF8505;
		padding: 11rpx 38rpx;
		border: 2rpx solid #FF8505;
	}

	.checkall {
		background-color: #FF8505 !important;
		color: #fff !important;
	}


	.payTypeClass {
		text-align: center;
		font-size: 28rpx;
		font-weight: bold;
		padding: 40rpx 0;
		width: 150rpx;
	}

	.sytbox {
		border: 1rpx solid #000;
		border-radius: 10rpx;
		padding: 15rpx 30rpx;
	}

	.itembox {
		margin-top: 15rpx;
		width: 200rpx;
		height: 100rpx;
		border: 1rpx solid #000;
		border-radius: 10rpx;
		font-size: 60rpx;
		font-weight: bold;
		box-shadow: 0rpx 4rpx 16rpx 2rpx rgba(0, 0, 0, 0.16);
	}

	.delitem {
		background-color: #013447 !important;
		color: #fff !important;
	}

	.sytsrk {

		text-align: right;
		font-size: 40rpx;
		font-weight: bold;
	}
</style>